package com.cloud.weixin.project.service.impl;

import com.cloud.common.core.asserts.ApiAssert;
import com.cloud.common.core.enums.ErrorCodeEnum;
import com.cloud.weixin.project.mapper.WxUserMapper;
import com.cloud.weixin.project.service.ITestService;
import io.seata.core.context.RootContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * <p>
 * Test 服务实现类
 * </p>
 *
 * @author Sam
 * @since 2021-05-17
 */
@Slf4j
@Service
public class TestServiceImpl implements ITestService {

    @Resource
    private WxUserMapper wxUserMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void seataReduceAmount() {
        String xid = RootContext.getXID();
        log.info("WEIXIN New Transaction Begins: " + xid);
        wxUserMapper.reduceAmount("1386884055525007418", 1);
        ApiAssert.failure(ErrorCodeEnum.INTERNAL_SERVER_ERROR.convert("测试中断"));
    }
}
